'/
' charutil.bmx
'/

superstrict

import BRL.Reflection

'// Ascii character library. Don't try to create instances of this type. The functions are in a type just to prevent
'// name clashing. Think of it kindof as a namespace.
type charutil

	function isDigit:byte(char:byte)
	
		return char >= $30 and char <= $39;
	
	end function
	
	function isHex:byte(c:int)
	
		return isDigit(c) ..
			or ((c >= $61) and (c <= $66)) .. '// a - f
			or ((c >= $41) and (c <= $46)); '// A - F		
	
	end function
	
	function isOctal:byte(c:int)
	
		return c >= $30 and c <= $37; '// 0 - 7
	
	end function
	
	function isLetter:byte(char:byte)
	
		return (char >= $61 and char <= $7A) .. '// a - z
			or (char >= $41 and char <= $5A); '// A - Z
	
	end function
	
	function isLetterOrDigit:byte(char:byte)
	
		return isLetter(char) or isDigit(char);
	
	end function
	
	function isWhitespace:byte(char:byte)
	
		return char = $20 or char = $09 .. '// space and tab
			or isNewline(char);
	
	end function
	
	function isTabOrSpace:byte(char:byte)
	
		return char = $20 or char = $09; '// space and tab
	
	end function
	
	function isNewline:byte(char:byte)
	
		return char = $0D or char = $0A; '// carriage return and line feed
	
	end function
	
	function isLinefeed:byte(char:byte)
	
		return char = $0A; '// line feed
	
	end function
	
	function isCarriageReturn:byte(char:byte)
	
		return char = $0D; '// carriage return
	
	end function
	
	method new()
	
		local id:string = TTypeId.forObject(self).name();
		runtimeError("Illegal to create an instance of a namespace class '" + id + "'.");
	
	end method

end type
